package hottargui.domain.objectServer;

import hottargui.domain.*;

/**
 * This implements the object server as a singleton
 * 
 * The Statemachine is implemented as a singleton and this reference cannot be 
 * changed, so it all-ready has one and only a one point of access. But for consistensis consideration is
 * also returned by this objectserver 
 * 
 * @author Per
 *
 */


public class StandardObjectServerSingleton implements ObjectServer {
	private GameFactory _gameFactory;
	private PlaceUnitsStrategy _placeUnitsStrategy;
	private volatile static StandardObjectServerSingleton uniqueInstance;
	private DeckOfCardsCreator _deckOfCardsCreator;
	
	
	
	public static ObjectServer getInstance() {
	
		if (uniqueInstance==null) {
			synchronized (StandardObjectServerSingleton.class) {
				if (uniqueInstance == null) {
					
					uniqueInstance = new StandardObjectServerSingleton();
				}
			} 
		}

		
		return uniqueInstance;
	}

	

	
	
	private StandardObjectServerSingleton() {
	
	}

	
	public PlaceUnitsStrategy getPlaceUnitsStrategy() {
		return _placeUnitsStrategy;
	}
	
	
	
	public void setCurrentFactory(GameFactory gameFactory) {
		_gameFactory = gameFactory; 
		reconfigureObjectServer();
	}
	

	public void registerStateMachine(SimpleStateMachine stm) {
		
	}
	
	private void reconfigureObjectServer() {
		_placeUnitsStrategy = _gameFactory.createPlaceUnitsStrategy();
	}
	
	
	public void registerDeckCreator(DeckOfCardsCreator deckOfCardsCreator) {
		_deckOfCardsCreator = deckOfCardsCreator;
	}


	public DeckOfCards getDeckOfCards() {
		return _deckOfCardsCreator.getDeckOfCards();
	}
	
	
	
}
